package com.wanmait.wanmarecruit.webController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.*;
import com.wanmait.wanmarecruit.service.CityService;
import com.wanmait.wanmarecruit.service.HotSearchService;
import com.wanmait.wanmarecruit.service.impl.CityServiceImpl;
import com.wanmait.wanmarecruit.service.impl.CompanyServiceImpl;
import com.wanmait.wanmarecruit.service.impl.PositionServiceImpl;
import com.wanmait.wanmarecruit.service.impl.PositionTypeServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("web")
public class WebIndexController {

    @Resource
    private PositionTypeServiceImpl positionTypeService;

    @Resource
    private PositionServiceImpl positionService;

    @Resource
    private CompanyServiceImpl companyService;

    @Resource
    private CityServiceImpl cityService;

    @Resource
    private HotSearchService hotSearchService;

    @RequestMapping("/personal/index")
    public ModelAndView index(HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView();

        PageInfo<PositionType> positionTypes = positionTypeService.indexSixPositionType();//主页六个一级招聘类型
        modelAndView.addObject("positionTypes",positionTypes);

        int positionCount = (int)positionService.count();
        modelAndView.addObject("positionCount",positionCount);

        List<Position> positions = positionService.getRandomEightPosition();
        modelAndView.addObject("positions",positions);

        List<Company> companies = companyService.getRandomEightHotCompany();
        modelAndView.addObject("companies",companies);

        List<City> cities = cityService.getRandomSevenHotCity();
        modelAndView.addObject("cities",cities);

        PageInfo<Position> positionPageInfo = positionService.getTopFivePosition();
        modelAndView.addObject("positionPageInfo",positionPageInfo);

        PageInfo<HotSearch> hotSearchPageInfo = hotSearchService.getTopTwelveHotSearch();
        modelAndView.addObject("hotSearchPageInfo",hotSearchPageInfo);

        return modelAndView;
    }

    @RequestMapping("/personal/inc/indexHead")
    public void indexHead(){

    }

    @RequestMapping("/personal/inc/indexFoot")
    public void indexFoot(){

    }

}
